/**
 * 
 */

/**
 * 刷新 admin news 列表
 */
function refreshAdminNewsTable(path, page){
	$("#admin_news_list_tbody").empty();
	$("input[type=checkbox]").removeAttr("checked");
	
	$.ajax({ 
		type:"POST",  
		url:path+"/newsAction_list.action?page="+page,
		data:{
			title:$("#a_s_title").val(), 
		},
		dataType:"json",
		success:function(result){
			if(result.success){  
				var newsList=result.data;
				if(newsList.length==0){ 
					$("#admin_news_list_tbody").empty();  
				}
				for(var i=0;i<newsList.length;i++){ 
					var newsinfo=newsList[i];   
					var $e=$('<tr><td class="" style="text-align:center;"> <input type="checkbox" name="abc" value="'+newsinfo.uuid+'" ></td><td class=""><a href="'+path+'/newsAction_getById.action?id='+newsinfo.uuid+'">'+newsinfo.title+'</a></td><td class="">'+newsinfo.newsTime+'</td></tr>'); 
					$("#admin_news_list_tbody").append($e); 
				}
				var $p=$('<tr><td colspan="3" style="text-align:center;"><div class="toCenter"> <div id="admin_news_pager"></div> </div></td></tr>');
				$("#admin_news_list_tbody").append($p); 
				initAdminNewsPage(path,result.pageBean.curPage,result.pageBean.totalPages); 
				
				 
			}else{
				alertError("操作失败");
			}
		}
	});
}

/**
 * 初始化admin news 列表分页插件 
 * @param curPage
 * @param totalPages 
 */
function initAdminNewsPage(path,curPage,totalPages){ 
	
	if(totalPages==0){
		totalPages=1; 
	}
	
	var options = {
			currentPage : curPage,
			totalPages : totalPages,
			numberOfPages : 5,  
			size:"normal",
			alignment:"right",  
			/*pageUrl : function(type, page, current) { 
				return path + "/blog_blogList.action?rows=10&page=" + page;
			}*/
			onPageClicked: function(e,originalEvent,type,page){
				refreshAdminNewsTable(path,page);
            }
		}
		$('#admin_news_pager').bootstrapPaginator(options);
}


/* 获取所有选中项的id字符串   */
function getChecked() {  
	var ids="";
	$("input[type=checkbox]").each(function() {
		if ($(this).prop("checked")) {
			ids+=$(this).val()+",";
		} 

	})
	return ids.substr(0,ids.length-1);
}

